約 1,701,310 件
https://w.atwiki.jp/atachi/pages/69.html
WPFToolkitで開発中のコンポーネントです。 まだ開発段階のため、WPFToolkitのライブラリ(WPFTools.DLL)にも含まれていません。 http //social.msdn.microsoft.com/Forums/ja-JP/wpfja/thread/9abc50e7-2104-4d80-8933-9e5f15545f2f http //social.msdn.microsoft.com/Forums/en-US/wpf/thread/215ac129-2b3e-45a3-833a-3990b6f9f0fd スクロールさせる? http //www.eggheadcafe.com/tutorials/aspnet/0939d60c-8e17-4a27-b898-1fc772d2d6f6/scrolling-in-wpf-toolkits-column-chart.aspx 線と丸の色 chartingToolkit LineSeries chartingToolkit LineSeries.DataPointStyle Style TargetType="{x Type chartingToolkit LineDataPoint}" Setter Property="Visibility" Value="Collapsed"/ Setter Property="Background" Value="Purple"/ /Style /chartingToolkit LineSeries.DataPointStyle /chartingToolkit LineSeries
https://w.atwiki.jp/atachi/pages/42.html
NotifyMessageとはタスクバーのタスクトレイに表示されるメッセージのこと。 参考サイト http //www.codeproject.com/KB/WPF/wpf_notifyicon.aspx
https://w.atwiki.jp/nina_a/pages/54.html
バインディング このページを編集 例(エレメントのプロパティ同士) Slider Height="33" HorizontalAlignment="Center" Width="400" Minimum="10" Maximum="100" Interval="1" Name="fslider"/ TextBlock HorizontalAlignment="Center" Margin="0,20,0,0" FontSize="{Binding ElementName=fslider, Path=Value}" こんにちは /TextBlock プログラムの場合は以下.面倒なので必要がなければXAMLでやる. // XAML Slider Height="33" HorizontalAlignment="Center" Width="400" Minimum="10" Maximum="100" Name="fslider"/ TextBlock HorizontalAlignment="Center" Margin="0,20,0,0" Name="ftext" こんにちは /TextBlock // C#Binding b = new Binding();b.Source = fslider;b.Path = new PropertyPath("Value");b.Mode = BindingMode.TwoWay;ftext.SetBinding(TextBlock.FontSizeProperty, b); 例(エレメントとオブジェクトのバインディング) Valueというプロパティを持つNumber型をバインディングしてみる. これがNumberクラス using System;using System.Collections.Generic;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Shapes;using System.ComponentModel; namespace Test{ public class Number INotifyPropertyChanged { public Number() { Value = 0; } public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(String info) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(info)); } // Valueプロパティ private Int32 _Value; public Int32 Value { get { return _Value; } set { _Value = value; NotifyPropertyChanged("Value"); } } }} Int32をStringに変換するIValueConverter using System;using System.Collections.Generic;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Shapes;using System.Globalization; namespace Test{ [ValueConversion(typeof(Int32), typeof(String))] public class NumberConverter IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return ((Int32) value).ToString(); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } }} そしてXAML. Window xmlns="http //schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns x="http //schemas.microsoft.com/winfx/2006/xaml" xmlns sys="clr-namespace System;assembly=mscorlib" xmlns local="clr-namespace Test" x Class="Test.MainWindow" x Name="Window" Title="MainWindow" Width="640" Height="480" Window.Resources local Number x Key="number"/ local NumberConverter x Key="nc"/ /Window.Resources StackPanel TextBlock HorizontalAlignment="Center" Margin="0,20,0,0" Text="{Binding Source={StaticResource number}, Path=Value, Converter={StaticResource nc}}"/ StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Button Content="Add 10" Margin="10" Name="add"/ Button Content="Subtract 10" Margin="10" Name="sub"/ /StackPanel /StackPanel /Window XAML.csはこんな感じ. public partial class MainWindow Window{ public MainWindow() { this.InitializeComponent(); Number num = (Number) this.FindResource("number"); this.add.Click += (e,s) = num.Value += 10; this.sub.Click += (e,s) = num.Value -= 10; }} カテゴリ:WPF 名前
https://w.atwiki.jp/nina_a/pages/55.html
ドラッグ・アンド・ドロップ(D D) このページを編集 概要 D Dとは,画面上のある要素をつかみ,移動させる方法のこと.本ページではウィンドウズからWPFアプリケーション,WPFアプリケーションからウィンドウズへのD Dについては解説せず,WPFアプリケーション内で完結するD Dについて説明する. D Dは,ドラッグされる物とドロップされる物の2つを設定すれば実現可能. ドラッグされる物 WPFではDragDropクラス( MSDN )の静的メソッドDoDragDropを呼び出すだけで良い.XAMLは後述. +ドラッグの開始 private void OnMouseDown(object s, System.Windows.Input.MouseButtonEventArgs e){ var sender = s as TextBlock; DragDrop.DoDragDrop( sender, // ドラッグされる物 sender.Text.Substring(sender.Text.Length-1), // 渡すデータ DragDropEffects.Copy); // D Dで許可するオペレーション} 普通は右クリックとかではドラッグは開始しないのでマウスの状態をチェックする. +左クリックによるドラッグの開始 private void OnMouseDown(object s, System.Windows.Input.MouseButtonEventArgs e){ var sender = s as TextBlock; if( e.LeftButton == MouseButtonState.Pressed e.RightButton == MouseButtonState.Released e.MiddleButton == MouseButtonState.Released ) DragDrop.DoDragDrop( sender, // ドラッグされる物 sender.Text.Substring(sender.Text.Length-1), // 渡すデータ DragDropEffects.Copy); // D Dで許可するオペレーション} ドロップされる物 XAMLでドロップを許可すればよい.Dropイベントが発生する.XAMLは後述. +ドロップの受け入れ private void OnDrop(object s, System.Windows.DragEventArgs e){ MessageBox.Show(e.Data.GetData(typeof(string)) + " is dropped.", "Dropped!");} XAML +ドラッグ・アンド・ドロップのサンプル Window xmlns="http //schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns x="http //schemas.microsoft.com/winfx/2006/xaml" x Class="WpfApplication1.MainWindow" x Name="Window" Title="MainWindow" Width="640" Height="480" Grid x Name="LayoutRoot" Grid.ColumnDefinitions ColumnDefinition Width="*"/ ColumnDefinition Width="*"/ ColumnDefinition Width="*"/ /Grid.ColumnDefinitions TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" MouseDown="OnMouseDown" Grab me! 1 /TextBlock TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" MouseDown="OnMouseDown" Grid.Column="1" Grab me! 2 /TextBlock TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" AllowDrop="True" Grid.Column="2" Drop="OnDrop" Drop to me! /TextBlock /Grid /Window ユーザへのフィードバック ドロップ先がドロップを受け入れることができるか,あるいは今ドロップした場合どの操作が行われるかをユーザに示すためにはDragEnterおよびDragOverイベントでEffectsを指定する. +ドロップエフェクトの指定サンプル // 関数名はDragOverだが,DragEnterもこれを呼び出しても動くprivate void OnDragOver(object sender, System.Windows.DragEventArgs e){ // ドロップされるデータがStringでなければ受け入れない if (!e.Data.GetDataPresent(typeof(System.String))) { e.Effects = DragDropEffects.None; return; } // ドロップされるデータ(String)がintに変換できなければ受け入れない var str = e.Data.GetData(typeof(string)) as string; int tmp; if (int.TryParse(str, out tmp)) e.Effects = DragDropEffects.Copy; else e.Effects = DragDropEffects.None;} より適当なD D 上記のコードでは,以下のように書き換えるとD Dできなくなる. +ボタンのドラッグ・アンド・ドロップ Button VerticalAlignment="Center" HorizontalAlignment="Center" MouseDown="OnMouseDown" Click="OnClick" Grab me! 1 /Button Button VerticalAlignment="Center" HorizontalAlignment="Center" MouseDown="OnMouseDown" Click="OnClick" Grid.Column="1" Grab me! 2 /Button TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" AllowDrop="True" Grid.Column="2" Drop="OnDrop" Drop to me! /TextBlock private void OnClick(object s, System.Windows.RoutedEventArgs e){ var sender = s as Button; var text = sender.Content as string; MessageBox.Show(text.Substring(text.Length-1) + " is clicked.", "Clicked!");} 少し調べるとOnMouseDown関数が呼び出されていないことが分かる(試しにMassageBox.ShowをOnMouseDownに追加してみると良い).これはButtonがClickイベントを実装しているため( 詳しくはここ ).このような場合はPreviewMouseDownを使う. +PreviewMouseDownによるドラッグアンドドロップ Button VerticalAlignment="Center" HorizontalAlignment="Center" MouseDown="OnMouseDown" Click="OnClick" Grab me! 1 /Button Button VerticalAlignment="Center" HorizontalAlignment="Center" PreviewMouseDown="OnMouseDown" Click="OnClick" Grid.Column="1" Grab me! 2 /Button TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" AllowDrop="True" Grid.Column="2" Drop="OnDrop" Drop to me! /TextBlock 上のコードでは,1つめのボタンはドラッグできないが,2つめのボタンはできる.ただし,2つめのボタンはClickイベントが発生しない.原因は勿論PreviewMouseDownでD Dを開始しているため. これへの対応としては,クリックされたまま一定距離を移動したらドラッグ開始という風にすれば良い. +PreviewMouseDownによるドラッグアンドドロップ2 Button VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="1" PreviewMouseMove="OnMouseMove" PreviewMouseDown="OnMouseDown" Click="OnClick" Grab me! 2 /Button private Point start;private Button downed; private void OnMouseDown(object s, System.Windows.Input.MouseButtonEventArgs e){ downed = s as Button; start = e.GetPosition(downed);} private void OnMouseMove(object s, System.Windows.Input.MouseEventArgs e){ var sender = (Button)s; if (downed != null downed == sender e.LeftButton == MouseButtonState.Pressed) { var current = e.GetPosition(sender); if (Math.Abs(current.X - start.X) SystemParameters.MinimumHorizontalDragDistance || Math.Abs(current.Y - start.Y) SystemParameters.MinimumVerticalDragDistance) { downed = null; DragDrop.DoDragDrop(sender, sender.Content, DragDropEffects.Copy); } }} private void OnDrop(object s, System.Windows.DragEventArgs e){ MessageBox.Show(e.Data.GetData(typeof(string)) + " is dropped.", "Dropped!");} これでクリックもドラッグもできるボタンができた. パネルなどのドラッグ・アンド・ドロップ パネルを丸ごとD Dしたい場合には,背景にTransparent(もしくは何らかの色など)を指定しておくこと.指定しない場合は,パネルの子要素の位置でクリックした場合のみD Dが開始され,それ以外の子要素がない場所でドラッグしようとしてもMouseDownイベントハンドラが呼び出されない. カテゴリ:WPF 名前
https://w.atwiki.jp/carenasgard/pages/25.html
後でWindows用とWPF用に書き換えるかもしれませんが、 今のところは共通としてダンプ。 Form上に動的コントロール配置(その1)、(その2) 自主学習用(microsoft) 窓の親子宣言 tech serialize,deserialize XML読み出し MemoryStream,その2
https://w.atwiki.jp/nina_a/pages/53.html
依存プロパティ(Dependency Property) このページを編集 依存プロパティを使う 依存プロパティを使うには,定義と登録を行うとともに,それをラップするプロパティを作成する. 定義は以下の通り.DependencyPropertyNameにはプロパティ名(たとえばMargin)の末尾にPropertyをつけたものにすると良い. public class ClassName SuperClass{ ... public static readonly DependencyProperty 【DependencyPropertyName】; ...} 登録は以下の通り.静的コンストラクタで登録を行っている. static ClassName(){ ... // 1. この依存プロパティで利用したいサービスを指定するFrameworkPropertyMetadataを作成 // 引数はMSDN参照 http //msdn.microsoft.com/ja-jp/library // /system.windows.frameworkpropertymetadata.frameworkpropertymetadata(v=VS.80).aspx FramrworkPropertyMetadata meta = new FrameworkPropertyMetadata( ... ); // 2. 依存プロパティを登録 【DependencyPropertyName】 = DependencyProperty.Register( "【PropertyName】", 【PropertyType】, 【このプロパティを所有する型】, 【1.のFrameworkPropertyMetadata(オプション)】, 【値を検証するコールバック(オプション)】); ...} ラップするプロパティはこんな感じ.というかこれ以外はすべきでないっぽい. public 【PropertyType】 【PropertyName】{ set { SetValue(【DependencyPropertyName】, value); } get { return (【PropertyType】) GetValue(【DependencyPropertyName】) }} FrameworkPropertyMetadata 詳細は MSDN で.フラグのプロパティのデフォルト値は全て偽. FrameworkPropertyMetadataのプロパティ 説明 AffectsArrange, AffectsMeasure, AffectsParentArrange, AffectsParentMeasure このプロパティが配置パス(あるいは測定パス,親要素の配置パス,測定パス)に影響を与えるかどうか AffectsRender (プロパティが配置や測定に影響を与えない) 何らかの方法でレイアウト全体に影響を及ぼす可能性があるかどうか BindsTwoWayByDefault 真ならプロパティの既定のバインドを双方向にする CoerceValueCallback CoerceValueCallback 実装への参照を取得・設定 DefaultUpdateSourceTrigger - DefaultValue プロパティの既定値 Inherits プロパティ値が継承されるかどうか IsAnimationProhibited 真ならアニメーション中は無効 IsNotDataBindable データバインディングをサポートしているかどうか Journal 真なら,ページベースのアプリケーションで値を保存する OverridesInheritanceBehavior 要素の論理ツリー内の特定のコンテンツ境界にまたがってプロパティ値の継承を評価するかどうか(?) PropertyChangedCallback 値が変わったときのコールバック SubPropertiesDoNotAffectRender サブプロパティがレンダーに影響するか(真ならサブプロパティの値が変わっても再描画されない) 値の設定,変更にともなう検証 DependencyPropertyではセッタで値の検証を行わず(行えず),ValidateValueCallbackとCoerceValueCallbackを使う.実行順序は CoerceValueCallbackで値を変更する機会が与えられる ValidateValueCallbackで正しい値か検証する PropertyChangedCallbackが実行される ValidateValueCallback 新しい値を受け取るか拒否するか決定する.DependencyProperty.Registerの引数で指定する. delegate bool ValidateValueCallback (Object value) CoerceValueCallback 新しい値を受け入れることの出来る値に変える.FrameworkPropertyMetadata.CoerceValueCallbackで指定する. delegate Object CoerceValueCallback (DependencyObject d,Object baseValue) カテゴリ:WPF 名前
https://w.atwiki.jp/carenasgard/pages/18.html
Windowsアプリケーションよりも適用可能幅が増えた様式。 使いこなせればきっと凄く役に立つ。 XAMLとGUIの両方を記述する必要ありな感じ。 暫くはこっちメインで書く予定。 WPF説明 (その1)入門記事 チュートリアル 色々な実装 Message Box 画像関連 文字関連 thumbthumb2 物体移動 コンテキストメニューを動的に設定物体移動を動的設定 動的生成 動的生成 動的生成 Command CommonDialog 進む、もどる? Binding資料 入力に対するEvent入力の概要 if (Mouse.LeftButton == MouseButtonState.Pressed) { // }
https://w.atwiki.jp/atachi/pages/43.html
参考サイト http //www.codeproject.com/KB/WPF/WPFDropDownColorPicker.aspx
https://w.atwiki.jp/atachi/pages/41.html
紹介のみ。 参考サイト http //www.codeproject.com/KB/WPF/Quick_WPf_MonthView_Cal-2.aspx
https://w.atwiki.jp/netnet/pages/41.html
WindowsFおrmでは、OverrideできたWndProcだけども、 WPFからはなくなっている。 しかし、それでも使いたい場合もあるだろう。 ということで、以下の参考 C# void Window1_Loaded(object sender, RoutedEventArgs e) { HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle); source.AddHook(new HwndSourceHook(WndProc)); } private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { //なにか } Source http //blogs.msdn.com/nickkramer/archive/2006/03/18/554235.aspx